package main

import "fmt"

type Books struct {
	title   string
	author  string
	subject string
	bookId  int
}

func main() {
	// 创建一个新的结构体
	books := Books{"go语言", "张三", "go语言教程", 1}
	fmt.Println(books)
	// key-value形式创建
	books = Books{title: "go语言", author: "张三", subject: "go语言教程", bookId: 2}
	fmt.Println(books)
	// 部分字段赋值
	books = Books{title: "go语言", author: "张三"}
	fmt.Println(books)

	// 访问结构体成员
	var book1 Books
	var book2 Books

	book1.title = "go语言"
	book1.author = "张三"
	book1.subject = "go语言教程"
	book1.bookId = 1

	book2.title = "go语言"
	book2.author = "张三"
	book2.subject = "go语言教程"
	book2.bookId = 2

	/* 打印 Book1 信息 */
	fmt.Printf("Book 1 title : %s\n", book1.title)
	fmt.Printf("Book 1 author : %s\n", book1.author)
	fmt.Printf("Book 1 subject : %s\n", book1.subject)
	fmt.Printf("Book 1 book_id : %d\n", book1.bookId)

	/* 打印 Book2 信息 */
	fmt.Printf("Book 2 title : %s\n", book2.title)
	fmt.Printf("Book 2 author : %s\n", book2.author)
	fmt.Printf("Book 2 subject : %s\n", book2.subject)
	fmt.Printf("Book 2 book_id : %d\n", book2.bookId)

	/* 打印 Book1 信息 */
	printBook(book1)

	/* 打印 Book2 信息 */
	printBook(book2)

	/* 打印 Book1 信息 */
	printBook1(&book1)

	/* 打印 Book2 信息 */
	printBook1(&book2)
}

func printBook(book Books) {
	fmt.Printf("Book title : %s\n", book.title)
	fmt.Printf("Book author : %s\n", book.author)
	fmt.Printf("Book subject : %s\n", book.subject)
	fmt.Printf("Book book_id : %d\n", book.bookId)
}

func printBook1(book *Books) {
	fmt.Printf("Book title : %s\n", book.title)
	fmt.Printf("Book author : %s\n", book.author)
	fmt.Printf("Book subject : %s\n", book.subject)
	fmt.Printf("Book book_id : %d\n", book.bookId)
}
